package com.song.controller;

import com.song.pojo.Student;
import com.song.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 宋伟宁
 * @Date 2024/1/15
 * @Version 1.0
 **/
@RestController
public class StudentController {

    @Resource
    private StudentService studentService;

    @GetMapping("/stus")
    public List<Student> list(){
        return this.studentService.findAll();
    }

    @GetMapping("/{id}")
    public Student getById(@PathVariable("id") Integer id){
        return this.studentService.findById(id);
    }

    @PostMapping("/")
    public boolean add(@RequestBody Student student){
        try {
            this.studentService.add(student);
            return true;
        }catch (Exception e){
            throw new RuntimeException(e.getMessage());
        }

    }
}
